import axios from 'axios'
import baseUrl from "./request/url";
// 导出Excel公用方法
export const post = (method, params) => {
    let data = params;
    if (!params instanceof FormData) {
        data = JSON.stringify(params);
    }
    return axios({
        method: "POST",
        url: `${baseUrl}${method}`,
        data,
        responseType: 'blob'
    }).then((res) => {

        return Promise.resolve(res.data);
    });
}
// 导出Excel公用方法
export function exportExcel(methods, data) {
    // let loadingInstance = Loading.service({
    //     lock: true,
    //     text: '正在请求数据中...',
    //     spinner: 'el-icon-loading',
    //     background: 'rgba(0, 0, 0, 0.7)'
    // });
    axios({
        method: "POST",
        url: data.url,
        data: data.data,
        responseType: 'blob'
    }).then((res) => {
        const link = document.getElementById('downlink')
        let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob)
        link.download = data.fileName //下载的文件名
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
        loadingInstance.close();
    }).catch(error => {
        // this.$Notice.error({
        //     title: '错误',
        //     desc: '网络连接错误'
        // })
        loadingInstance.close();
        Message.error('网络连接错误')
    })
}

/**
* @name 根据楼宇信息获取栋长和房东信息，生成XLS文件
* @param {Object} args 入参
* @param {Array} args.ids 
**/
export const cesiumExportBuildingInfo = (ids) => {
    return post("/cesium/export/buildingInfo", ids)
}
